{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "SinglePhaseFlowSimulator1.ipynb",
      "provenance": [],
      "authorship_tag": "ABX9TyPw0IxOe/9y7I5wGE0I0TGm",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/Divyanshu-ISM/Oil-and-Gas-data-analysis/blob/master/SinglePhaseFlowSimulator1.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "UrwtX3mXK5_e",
        "colab_type": "text"
      },
      "source": [
        "# **Just a Simple Reservoir Simulation for a 1 Phase , Incompressible Flow in 1D**\n",
        "\n",
        "## - The aim is to clearly understand the workflow."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vV_qLkkgLNFj",
        "colab_type": "text"
      },
      "source": [
        " ###              --- Divyanshu Vyas (IIT ISM Dhanbad, India)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "M9FOHy8tBz9A",
        "colab_type": "text"
      },
      "source": [
        "A single-phase fluid reservoir is described by four equal blocks. The reservoir is horizontal and has homogeneous and\n",
        "isotropic rock properties, k = 270 md and $\\phi$ = 0.27. The gridblock dimensions\n",
        "are $ \\triangle $ x = 300 ft, $\\triangle\\$ y = 350 ft, and h = 40 ft. The reservoir fluid properties are\n",
        "B = B ° = 1 RB/STB, density = 50 Ibm/ft 3, and visc = 0.5 cp. The reservoir left\n",
        "boundary is kept at constant pressure of 4000 psia, and the reservoir right\n",
        "boundary is sealed off to flow. A 7 in vertical well was drilled at the center of\n",
        "gridblock 4. The well produces 600 STB/D of fluid and has a skin factor of 1.5.\n",
        "Assuming that the reservoir rock and fluid are incompressible, find the pressure\n",
        "distribution in the reservoir and the FBHP of the well. Perform a material balance\n",
        "check"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "X4PyHeb0_OK4",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# 4 Blocks 1D (x-direction) flow. --> 1x4 array. \n",
        "\n",
        "k = 270\n",
        "A = 350*40\n",
        "\n",
        "u = 0.5\n",
        "B = 1\n",
        "\n",
        "rho = 50 #lbm/ft3\n",
        "\n",
        "l = 300 #delta x\n"
      ],
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QAl366CiDNae",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# For block 1 -> Flow equation :\n",
        "# Tx(p2 - p1) + qbw = 0 \n",
        "# Tx.p2 - Tx.p1 + 2.Tx.5000 - 2.Tx.p1 = 0 \n",
        "# Tx.p2 - 3.Tx.p1 + 2.Tx.5000 = 0\n",
        "\n",
        "Tx = (0.001127*k*A)/(u*B*l)"
      ],
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4Xa-FUVaEkQY",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "e9e81e25-966a-4971-b43c-ddf3a2f4722a"
      },
      "source": [
        "print(Tx,3*Tx, 2*Tx*4000)"
      ],
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "28.4004 85.2012 227203.2\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bTUhxoCpGIU3",
        "colab_type": "text"
      },
      "source": [
        "#1. -85.2012 P1  + 28.4004 P2 + 0 P3 + 0 P4 = - 227203.2"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7Dx7OetRETYC",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#for block 2 -->\n",
        "\n",
        "# Tx(p1-p2) + Tx(p3-p2) = 0\n",
        "\n",
        "# Tx.p1 - Tx.p2 + Tx.p3 - Tx.p2 = 0 \n",
        "\n",
        "# Tx.p1 - 2.Tx.P2 + Tx.P3 + 0. P4\n"
      ],
      "execution_count": 7,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lDnPmOoFG8GP",
        "colab_type": "text"
      },
      "source": [
        "# 2. 28.4004 P1 - 56.8008 P2 + 28.4004 P3 + 0.P4 = 0"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oNpjBFWjG7W-",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#For block 3 -->\n",
        "\n",
        "# Tx(P2-P3) + Tx(P4 - P3) = 0 \n",
        "\n",
        "# TxP2 - 2TxP3 + TxP4 = 0"
      ],
      "execution_count": 8,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "A2sZxtk2HhA-",
        "colab_type": "text"
      },
      "source": [
        "# 3. 0 P1 + 28.4004 P2 - 56.8008 P3 + 28.4004 P4 = 0"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Q-EmZHU3Hfpq",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#for block 4 --->\n",
        "\n",
        "# Tx(P3 - P4) + 0 - 600 = 0"
      ],
      "execution_count": 9,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bicF69SgH-hL",
        "colab_type": "text"
      },
      "source": [
        "#4. 0 P1 + 0 P2 + 28.4004 P3 - 28.4004 P4 = 600"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "knJGODnAIqH1",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import numpy as np\n"
      ],
      "execution_count": 11,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vN1IVYFkH90k",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# SO the Pressure coefficient matrix becomes \n",
        "\n",
        "C = np.array( [[-85.2012,28.4004,0,0],\n",
        "               [28.4004,-56.8008,28.4004,0],\n",
        "               [0,28.4004,-56.8008,28.4004],\n",
        "               [0,0,28.4004,-28.4004]])"
      ],
      "execution_count": 12,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Wfuiw2-PIoqX",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 85
        },
        "outputId": "a699eeb3-66d2-45b6-fb5e-afacbb50cde5"
      },
      "source": [
        "C"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[-85.2012,  28.4004,   0.    ,   0.    ],\n",
              "       [ 28.4004, -56.8008,  28.4004,   0.    ],\n",
              "       [  0.    ,  28.4004, -56.8008,  28.4004],\n",
              "       [  0.    ,   0.    ,  28.4004, -28.4004]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 13
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "AKSjnrV-Itm9",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Now the rhs constants matrix = \n",
        "\n",
        "b = np.array([-227203.2,0,0,600]).reshape(4,1)"
      ],
      "execution_count": 22,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kvgsXFbjJI16",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 85
        },
        "outputId": "a09ead24-6055-4771-8249-2a800103763f"
      },
      "source": [
        "b"
      ],
      "execution_count": 23,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[-227203.2],\n",
              "       [      0. ],\n",
              "       [      0. ],\n",
              "       [    600. ]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 23
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BQ6bjCetJJxE",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "C_inv = np.linalg.inv(C)"
      ],
      "execution_count": 24,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ml3QI1THJdxm",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "p = np.dot(C_inv,b)"
      ],
      "execution_count": 25,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "66wVbXpGJeyy",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 85
        },
        "outputId": "547d46a4-c27a-4f18-bd4e-eae1acc341a0"
      },
      "source": [
        "p"
      ],
      "execution_count": 26,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[3989.4367685 ],\n",
              "       [3968.31030549],\n",
              "       [3947.18384248],\n",
              "       [3926.05737947]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 26
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CpOGx0w1J2QZ",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#CORRECTOO! These are the pressures of the gridblocks 1,2,3,4 respectively. "
      ],
      "execution_count": 28,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3jKl6x9FKRte",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}